﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using app_common;
namespace tpos_custom_control
{
    public partial class uc_textbox : UserControl
    {
        private Color FoCusBackColor;
        private Color LossFoCusBackColor;
        private bool IsFocus;

        public uc_textbox()
        {
            InitializeComponent();
        }

        private void uc_textbox_Load(object sender, EventArgs e)
        {
            this.FoCusBackColor = Color.Cyan;
            this.LossFoCusBackColor = Color.White;
            txt.Top = 0;
            txt.Left = 0;
            this.Height = txt.Height;
            this.Width = txt.Width;
        }

        public bool uc_Multiline
        {
            get { return txt.Multiline; }
            set { txt.Multiline = value; }
        }

        public string uc_Text {
            get { return txt.Text; }
            set { txt.Text = value; }
        }
        
        public Color uc_BackColor {
            get { return txt.BackColor; }
            set { txt.BackColor = value; }
        }

        public Color uc_EnterBackColor
        {
            get { return txt.BackColor; }
            set { txt.BackColor = value; }
        }

        public Color uc_LeaveFocusBackColor
        {
            get { return txt.BackColor; }
            set { txt.BackColor = value; }
        }

        private void txt_Enter(object sender, EventArgs e)
        {
            this.uc_EnterBackColor = this.FoCusBackColor;
            this.uc_Forcus = true;
        }

        private void txt_Leave(object sender, EventArgs e)
        {
            this.uc_LeaveFocusBackColor = this.LossFoCusBackColor;
            this.uc_Forcus = false;
        }

        private void uc_textbox_Resize(object sender, EventArgs e)
        {
            if (this.uc_Multiline == true)
            {
                txt.Height = this.Height;
            }
            else {
                txt.Height = this.Height;
            }
            txt.Width = this.Width;
        }

        public char uc_PasswordChar {
            get { return txt.PasswordChar; }
            set { txt.PasswordChar = value; }
        }

        public Font uc_Font{
            get { return txt.Font; }
            set { txt.Font = value; }
        }

        public bool uc_Forcus {
            get { return this.IsFocus; }
            set { 
                    this.IsFocus = value;
                    if (this.IsFocus == true) {
                        txt.Focus();
                    }
                }
        }

        private void txt_KeyUp(object sender, KeyEventArgs e)
        {
            if (APP_DELEGATE.TEXTBOX_KEYUP != null)
            {
                APP_DELEGATE.TEXTBOX_KEYUP(sender, e);
            }
        }
    }
}
